package com.hmall.search.config;/**
 * @author wl
 * @version 1.0
 * @since 2025-09-10 14:43
 */

import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
import co.elastic.clients.transport.rest_client.RestClientTransport;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 *des:
 *data Created in 2025-09-10 14-43
 */
@Configuration
public class EsConfig {



    @Bean
    public ElasticsearchClient esClient() {
        // 创建 ObjectMapper 实例
        ObjectMapper objectMapper = new ObjectMapper();
        // 添加 JavaTimeModule 以支持 LocalDateTime 类型
        objectMapper.registerModule(new JavaTimeModule());
      return   new ElasticsearchClient(
                new RestClientTransport(
                        RestClient.builder(new HttpHost("192.168.101.68",9200)) .build(),
                        new JacksonJsonpMapper(objectMapper)
                )
        );
    }
}
